<?php
/**
 * Created by PhpStorm.
 * User: liuhongchuan
 * Date: 2018/4/26
 * Time: 14:39
 *
 * 管理员登录日志
 */

namespace app\operation\controller;

use app\common\controller\OperationBase;

class LoginLog extends OperationBase{

	function _initialize() {
		parent::_initialize();  
    }

	public function index(){
        $auth_group = sp_get_auth_menu_3("20001002");
        $shops = db("shop")->where(array("parent_id" => array("neq", 0)))->order("parent_id desc, shop_name desc")->column("id, shop_name");
        $this->assign("shops", $shops);
        $this->assign("menus", $auth_group);
        echo $this->fetch();
	}

    /**
     * @return array
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
	public function ajaxIndex(){
        $shop_id = input("shop_id/d");
        $account = input("account/s");
		$soft_version=input("soft_version");
        $where = array();
        if (!empty($shop_id)) {
            $where["a.shop_id"] = array("eq", $shop_id);
        }
        if (!empty($account)) {
            $where["ad.account"] = array("like", "%{$account}%");
        }
		if (!empty($soft_version)) {
            $where["a.soft_version"] = array("like", "%{$soft_version}%");
        }

        $draw = input("draw",0) + 1;//请求时间

        $total = db("admin_log")->alias('a')
            ->join("m_admin ad", "ad.id = a.admin_id", "left")
            ->where($where)
            ->count(1);
        $list = db("admin_log")->alias("a")
            ->field("a.create_time, a.soft_version, ad.mobile, ad.name, a.id, a.update_time, a.ip, ad.account, s.shop_name")
            ->join("m_shop s","a.shop_id = s.id","left")
            ->join("m_admin ad", "ad.id = a.admin_id", "left")
            ->where($where)
            ->order($this->get_order())
            ->limit($this->get_limit())
            ->select();
        $this->ajax(array('pageData' => $list, 'total' => $total, "draw" => $draw));
	}

}
